package com.example.demo.service.Impl;

import com.example.demo.entity.Complaint;
import com.example.demo.entity.User;
import com.example.demo.mapper.AttractionMapper;
import com.example.demo.mapper.ComplaintMapper;
import com.example.demo.pojo.ComplaintDTO;
import com.example.demo.service.ComplaintService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ComplaintServiceImpl implements ComplaintService {
    @Resource
    ComplaintMapper complaintMapper;
    @Resource
    AttractionMapper attractionMapper;
    @Override
    public PageInfo<Complaint> list(ComplaintDTO complaintDTO) {
        List<Complaint> complaints = complaintMapper.list(complaintDTO);
        PageInfo<Complaint> complaintPageInfo = new PageInfo<>(complaints);
        return complaintPageInfo;
    }

    @Override
    public int publish(ComplaintDTO complaintDTO) {
        String attractionName = complaintDTO.getScene();
        Integer attractionId = attractionMapper.selectIdByName(attractionName);
        Complaint complaint = new Complaint();
        complaint.setUser_id(30);
        complaint.setAttraction_id(attractionId);
        complaint.setVisitor_phone(complaintDTO.getPhone());
        complaint.setInfo(complaintDTO.getContent());
        complaint.setCreate_time(new Date());
        complaint.setStatus("处理中");
        return complaintMapper.add(complaint);
    }
}
